﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;

namespace ClassLibrary2
{
    public class MasterElementList : List<MasterElement>
    {
        public MasterElement parent;

        public MasterElementList(MasterElement parent)
        {
            this.parent = parent;
        }

        public void Add(MasterElement masterElement)
        {
            if (base.IndexOf(masterElement) != -1)
            {
                return;
            }
            else
            {
                if (masterElement.Parent == null)
                {
                    masterElement.Parent = parent;
                }
                if (base.Contains(masterElement.Parent))
                {
                    masterElement.Parent = base[base.IndexOf(masterElement.Parent)];
                    //base[base.IndexOf(masterElement.Parent)].AddChild(masterElement);
                }
                if (!base.Contains(masterElement))
                {
                    base.Add(masterElement);
                }
            }
        }

        public MasterElement findMasterElement(MasterElement me)
        {
            if (base.IndexOf(me) != -1)
            {
                return base[base.IndexOf(me)];
            }
            return null;
        }

    }
}
